package android.eventfinder;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;

public class Event {
	protected Date performanceDateTime;
	protected String artists;
	protected String title;
	protected ArrayList<String> tags;
	
		
	Event(Date dateTime, String name) {
		performanceDateTime = dateTime;
		title = name;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	

	public Date getDateTime() {
		return performanceDateTime;
	}
	public String getDateString() {
		String dates[] = new String[7];
		dates[0] = "Sat";
		dates[1] = "Sun";
		dates[2] = "Mon";
		dates[3] = "Tues";
		dates[4] = "Wed";
		dates[5] = "Thurs";
		dates[6] = "Fri";
		
		String months[] = new String[12];
		months[0] = "January";
		months[1] = "February";
		months[2] = "March";
		months[3] = "April";
		months[4] = "May";
		months[5] = "June";
		months[6] = "July";
		months[7] = "August";
		months[8] = "September";
		months[9] = "October";
		months[10] = "November";
		months[11] = "December";
		
		
		int dayOfWeek = performanceDateTime.getDay();
		int minutes = performanceDateTime.getMinutes();
		
		String theMinutes = "" + minutes;
		if (minutes < 10) {
			theMinutes = "0" + theMinutes;
		}
		String AmPm = "PM";
		
		if (performanceDateTime.getHours() < 12) {
			AmPm = "AM";
		}
		
		String theHours = "" + performanceDateTime.getHours()%12;
		if (performanceDateTime.getHours() == 0) {
			theHours = "12";
		}
	
		return dates[dayOfWeek] + " " + months[performanceDateTime.getMonth()] + " " + 
				performanceDateTime.getDate() + " " + theHours + ":" +
				theMinutes + " " + AmPm;
	}

	public String getArtists() {
		return artists;
	}
	public void setArtist(String artist) {
		artists = artist;
	}
	
	public ArrayList<String> getTags() {
		return tags;
	}
	public void setTags(ArrayList<String> newTags) {
		tags = newTags;
	}
	public String showTags() {
		String retString = "";
		
		for(int i = 0; i < tags.size(); i++ ) {
			if (i == (tags.size() - 1)) {
				retString += tags.get(i);	
			}
			else {
				retString += tags.get(i) + ", ";	
			}
			
		}
		
		return retString;
	}

	

	
	
}

@SuppressWarnings("rawtypes")
class timeComparator implements Comparator {
	public int compare(Object a, Object e) {
		final int BEFORE = -1;
		final int EQUAL = 0;
		final int AFTER = 1;
		if(((Event) a).getDateTime().before(((Event)e).getDateTime()))
			return BEFORE;
		if(((Event)a).getDateTime().equals(((Event)e).getDateTime()))
			return EQUAL;
		else
			return AFTER;
	}
}